#include <QLineEdit>
#include <QLabel>
#include <QPushButton>
#include <QFormLayout>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QString>
#include <QSpacerItem>
#include <QDebug>

#include "LoginWidget.hpp"

LoginWidget::LoginWidget(QWidget *parent) :
    QWidget(parent)
{
    QFormLayout *formLayout = new QFormLayout();
    m_nameLine = new QLineEdit(this);
    m_nameLine->setMaxLength(maxInputLength);
    formLayout->addRow(QString::fromUtf8(
                           tr("Имя").toStdString().c_str()),
                       m_nameLine);
    m_passwordLine = new QLineEdit(this);
    m_passwordLine->setEchoMode(QLineEdit::Password);
    m_passwordLine->setMaxLength(maxInputLength);
    formLayout->addRow(QString::fromUtf8(
                           tr("Пароль").toStdString().c_str()),
                       m_passwordLine);
    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addStretch();
    m_enterButton =
            new QPushButton(
                QString::fromUtf8(
                    tr("Войти").toStdString().c_str()),
                this);
    buttonLayout->addWidget(m_enterButton);
    QVBoxLayout *mainLayout = new QVBoxLayout();
    mainLayout->addLayout(formLayout);
    mainLayout->addLayout(buttonLayout);
    mainLayout->addStretch();
    setLayout(mainLayout);

    connect(m_enterButton, SIGNAL(clicked()),
            this, SLOT(onEnterClicked()));
}


void LoginWidget::onEnterClicked()
{
    qDebug() << "emit authorization";
    emit authorization(m_nameLine->text(), m_passwordLine->text());
}
